package com.yy.ent.mobile.ui.live;
import android.os.Bundle;
import android.view.KeyEvent;
import com.yy.ent.cherry.ioc.event.ContentView;
import com.yy.ent.mobile.ui.base.ShowActivity;
import com.yy.ent.show.ui.R;

/**
 * Created by dengqu on 2016/1/21.
 */
@ContentView(R.layout.activity_show_live)
public class LiveActivity extends ShowActivity {
    private final static String TAG = "LiveActivity";
    private LiveFragment liveFragment;
    private boolean isAnchor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        isAnchor= getIntent().getBooleanExtra("isAnchor", false);
        initView();
    }


    private void initView() {
        liveFragment = (LiveFragment) getSupportFragmentManager().findFragmentByTag(LiveFragment.FRAGMENT_TAG);
        if (null == liveFragment) {
            liveFragment = new LiveFragment();
        }
        getSupportFragmentManager().beginTransaction().replace(R.id.live_view, liveFragment, LiveFragment.FRAGMENT_TAG).commitAllowingStateLoss();
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && (event.getAction() == KeyEvent.ACTION_DOWN)) {
            if (isAnchor) {
                liveFragment.popLeaveWindow();
            }else{
                finish();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}
